<?php 
/*
**模型：关注，跟随
**model/class.follow.php
**By QINIAO
*/

class qiFollow{
	var $db;
	
	function qiFollow($dbhandle)
	{
		$this->db = $dbhandle;
	}
	//加关注
    function ManageFollow($uid,$fid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."follow where uid=$uid and fid=$fid");
	$num = $this->db->num_rows($res);
	if(empty($num))
	{
	$this->db->query("insert into ".DB_PREFIX."follow (uid,fid) values ('$uid','$fid')");
	}
	else
	{
	$this->db->query("DELETE FROM ".DB_PREFIX."follow where uid=$uid and fid=$fid"); 
	}
	}
	//判断是否关注
	function isFollow($uid,$fid)
	{
	if(empty($uid))
	{
	echo "+加关注";
	}
	elseif(!empty($uid))
	{
	$res = $this->db->query("select * from ".DB_PREFIX."follow where uid=$uid and fid=$fid");
	$num = $this->db->num_rows($res);
	if(empty($num))
	{
	echo "+加关注";
	}else
	{
	echo "取消关注";
	}
	}
	}
	//显示某一用户关注的用户列表
	function getUidFollow($uid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."follow where uid=$uid");
	$followDate = array();
	while($row = $this->db->fetch_array($res))
	{
	$followDate[] = $row;
	}
	return $followDate;
	}
	//显示某一用户关注的用户数
	function getUidFollowNum($uid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."follow where uid=$uid");
	$follownum = $this->db->num_rows($res);
	return $follownum;
	}
	
	//显示某一用户被关注的用户列表
	function getFidFollow($fid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."follow where fid=$fid");
	$followDate = array();
	while($row = $this->db->fetch_array($res))
	{
	$followDate[] = $row;
	}
	return $followDate;
	}
	//显示某一用户被关注的用户数
	function getFidFollowNum($fid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."follow where fid=$fid");
	$follownum = $this->db->num_rows($res);
	return $follownum;
	}

	}

?>